﻿using System;
using System.Linq;
using System.Transactions;
using NUnit.Framework;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.Test.FakeData;

namespace ProjetoComperio.Test.BusinessLogicLayer
{
    [TestFixture]
    public class EducationalITApplicationBLLTest
    {
        EducationalITApplicationBLL educationalITApplicationBLL;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {

            educationalITApplicationBLL = new EducationalITApplicationBLL();
        }

        [SetUp]
        public void SetUp()
        {
            educationalITApplicationBLL.InitializeDataContext(new FakeComperioEntitiesDataModel());
        }
        [Test]
        public void TestRetrieveEducationITApplications()
        {
            Assert.AreEqual(7, educationalITApplicationBLL.RetrieveEducationalITApplications().Count());
        }

        [Test]
        [Category("lazy")]
        public void TestCreateEducationalITApplication_Valid()
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {

                Student student = StudentBLLTest.CreateFakeStudent();
                String password = "1234ABCD_90s";
                string UserName = "ASHD_87s";
                StudentBLL studentBLL = new StudentBLL();
                studentBLL.Create(student, UserName, password);

                EducationalITApplication educationalItApplication = new EducationalITApplication();
                educationalItApplication.AcademicPerson = student;
                educationalItApplication.Title = "title";
                educationalItApplication.RegisterDate = DateTime.Now;
                educationalItApplication.SourceInfo = "sourceInfo";
                educationalItApplication.AdditionalInfo = "ai";
                educationalItApplication.Description = "description";
                EducationalITApplicationBLL educationalItApplicationBLL = new EducationalITApplicationBLL();
                educationalItApplicationBLL.Create(educationalItApplication);
                var storedEducationalITApplication =
                    educationalItApplicationBLL.RetrieveEducationalITApplications().Where(a => a.RegisterDate == educationalItApplication.RegisterDate).FirstOrDefault();
                Assert.IsNotNull(storedEducationalITApplication);
                transactionScope.Dispose();
            }
        }
    }
}
